<template>
  <div id="index">
    <el-container>
      <!-- 顶部 -->
      <el-header>
        <h2>后台管理系统</h2>
        <div @mouseover="showDialog=true" @mouseleave="showDialog=false">
          <span class="iconfont icon-yonghu1"></span>
        </div>
        <div
          class="dialog"
          v-show="showDialog"
          @mouseover="enterdailog"
          @mouseleave="showDialog=false"
        >
          <span @click=" dialogFormVisible = true">修改密码</span>
          <br />
          <span @click="exit()">退出</span>
        </div>
      </el-header>
      <!-- 侧边导航栏 -->
      <el-container>
        <el-aside width="200px">
          <el-col>
            <el-menu text-color="#666666" active-text-color="#0084FF">
              <!--1. 一级菜单 -->
              <el-submenu index="1">
                <template slot="title">
                  <span class="iconfont icon-yonghu"></span>
                  <span>用&emsp;户&emsp;管&emsp;理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item-group>
                  <el-menu-item index="1-1" @click="componentId='Teacher'">
                    <span class="iconfont icon-jiaoshiguanli"></span>教师管理
                  </el-menu-item>
                  <el-menu-item index="1-2" @click="componentId='Students'">
                    <span class="iconfont icon-xuesheng"></span>学生管理
                  </el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <!-- 2.一级菜单 -->
              <el-submenu index="2">
                <template slot="title">
                  <span class="iconfont icon-gonggao"></span>
                  <span>公&emsp;告&emsp;管&emsp;理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item-group>
                  <el-menu-item index="2-1" @click="componentId='AdminNotice'">
                    <span class="iconfont icon-guanliyuan"></span>管理员公告
                  </el-menu-item>
                  <el-menu-item index="2-2" @click="componentId='TeacherNotice'">
                    <span class="iconfont icon-jiaoshiguanli1"></span>教师公告
                  </el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <!--3. 一级菜单 -->
              <el-submenu index="3">
                <template slot="title">
                  <span class="iconfont icon-zhaoxueyuan"></span>
                  <span>校&emsp;园&emsp;管&emsp;理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item-group>
                  <el-menu-item index="3-1" @click="componentId='College'">
                    <span class="iconfont icon-xiaoyuan"></span>院别管理
                  </el-menu-item>
                  <el-menu-item index="3-2" @click="componentId='Subject'">
                    <span class="iconfont icon-zhuanye"></span>专业管理
                  </el-menu-item>
                  <el-menu-item index="3-3" @click="componentId='Class'">
                    <span class="iconfont icon-banjiguanli"></span>班级管理
                  </el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <!--4.一级菜单  -->
              <el-submenu index="4">
                <template slot="title">
                  <span class="iconfont icon-biaodan"></span>
                  <span>收集表管理</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item-group>
                  <el-menu-item index="4-1" @click="componentId='Collection'">
                    <span class="iconfont icon-xueshengxinxicaiji"></span>收集表管理
                  </el-menu-item>
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-aside>
        <!-- 中间内容 -->
        <el-main>
          <component :is="componentId" v-if="isRouterAlive"></component>
        </el-main>
      </el-container>
    </el-container>
    <!-- 修改密码弹出框 -->
    <el-dialog title="修改密码" :visible.sync=" dialogFormVisible" width="30%" center>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="原密码" prop="pwd">
          <el-input v-model.number="ruleForm.age"></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="pass">
          <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 修改密码弹出框end -->
  </div>
</template>
<script>
import AdminNotice from "../components/comment/AdminNotice.vue";
import TeacherNotice from "../components/comment/TeacherNotice.vue";
import College from "../components/campus/College.vue";
import Subject from "../components/campus/Subject.vue";
import Class from "../components/campus/Class.vue";
import Teacher from "../components/user/Teacher.vue";
import Students from "../components/user/Students.vue";
import Collection from "../components/collection/Collentions.vue";
export default {
  name: "index",
  // 局部刷新
   provide() {
    return {
      reload: this.reload
    };
  },
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      // 局部刷新
      isRouterAlive:true,
      formLabelWidth: "100px",
      componentId: "AdminNotice",
      showDialog: false,
      dialogFormVisible: false,
      form: {
        name: "",
        password: ""
      },
      ruleForm: {
        pwd: "",
        pass: "",
        checkPass: ""
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }]
      }
    };
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(() => {
        this.isRouterAlive = true;
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    enterdailog() {
      this.showDialog = true;
    },
    // 退出登录
    exit() {
      this.$put_form(this.$urlPath.user + "/admin/outLogin").then(resp => {
        if (resp.code != 200) {
          return this.$message.error("退出登录失败！");
        }
        // 退出登录
        this.$router.push({ path: "/login" });
      });
    }
  },
  components: {
    AdminNotice,
    TeacherNotice,
    Teacher,
    Students,
    College,
    Subject,
    Class,
    Collection
  }
};
</script>
<style lang="less">
@import "../assets/less/index.less";
</style>
<style >
* {
  font-family: abc;
}
</style>